from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-22 14:02:37.974981
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 22, Mar, 2022
Time: 14:02:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.6215
Nobs: 602.000 HQIC: -49.0233
Log likelihood: 7235.28 FPE: 3.96505e-22
AIC: -49.2794 Det(Omega_mle): 3.41865e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350354 0.066631 5.258 0.000
L1.Burgenland 0.107284 0.040557 2.645 0.008
L1.Kärnten -0.110691 0.021216 -5.217 0.000
L1.Niederösterreich 0.191802 0.084783 2.262 0.024
L1.Oberösterreich 0.121131 0.083609 1.449 0.147
L1.Salzburg 0.259102 0.043027 6.022 0.000
L1.Steiermark 0.036965 0.056809 0.651 0.515
L1.Tirol 0.102669 0.045829 2.240 0.025
L1.Vorarlberg -0.067800 0.040468 -1.675 0.094
L1.Wien 0.016472 0.074412 0.221 0.825
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054748 0.143138 0.382 0.702
L1.Burgenland -0.037838 0.087125 -0.434 0.664
L1.Kärnten 0.042020 0.045576 0.922 0.357
L1.Niederösterreich -0.203016 0.182133 -1.115 0.265
L1.Oberösterreich 0.454645 0.179612 2.531 0.011
L1.Salzburg 0.282787 0.092431 3.059 0.002
L1.Steiermark 0.112611 0.122040 0.923 0.356
L1.Tirol 0.305927 0.098451 3.107 0.002
L1.Vorarlberg 0.026566 0.086935 0.306 0.760
L1.Wien -0.029514 0.159854 -0.185 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198661 0.034053 5.834 0.000
L1.Burgenland 0.089060 0.020727 4.297 0.000
L1.Kärnten -0.007167 0.010843 -0.661 0.509
L1.Niederösterreich 0.241799 0.043330 5.580 0.000
L1.Oberösterreich 0.159502 0.042730 3.733 0.000
L1.Salzburg 0.040169 0.021990 1.827 0.068
L1.Steiermark 0.027192 0.029034 0.937 0.349
L1.Tirol 0.081910 0.023422 3.497 0.000
L1.Vorarlberg 0.054014 0.020682 2.612 0.009
L1.Wien 0.117016 0.038030 3.077 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118780 0.034037 3.490 0.000
L1.Burgenland 0.042953 0.020718 2.073 0.038
L1.Kärnten -0.012924 0.010838 -1.193 0.233
L1.Niederösterreich 0.171630 0.043310 3.963 0.000
L1.Oberösterreich 0.335677 0.042710 7.859 0.000
L1.Salzburg 0.099876 0.021979 4.544 0.000
L1.Steiermark 0.111934 0.029020 3.857 0.000
L1.Tirol 0.089192 0.023411 3.810 0.000
L1.Vorarlberg 0.060632 0.020672 2.933 0.003
L1.Wien -0.017938 0.038012 -0.472 0.637
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126709 0.063869 1.984 0.047
L1.Burgenland -0.044643 0.038876 -1.148 0.251
L1.Kärnten -0.045329 0.020336 -2.229 0.026
L1.Niederösterreich 0.135511 0.081268 1.667 0.095
L1.Oberösterreich 0.161180 0.080143 2.011 0.044
L1.Salzburg 0.284652 0.041243 6.902 0.000
L1.Steiermark 0.058223 0.054454 1.069 0.285
L1.Tirol 0.158049 0.043929 3.598 0.000
L1.Vorarlberg 0.097398 0.038791 2.511 0.012
L1.Wien 0.071337 0.071327 1.000 0.317
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077187 0.049846 1.548 0.122
L1.Burgenland 0.025545 0.030341 0.842 0.400
L1.Kärnten 0.053183 0.015871 3.351 0.001
L1.Niederösterreich 0.190185 0.063426 2.999 0.003
L1.Oberösterreich 0.330538 0.062548 5.285 0.000
L1.Salzburg 0.035050 0.032188 1.089 0.276
L1.Steiermark 0.008309 0.042499 0.196 0.845
L1.Tirol 0.119631 0.034285 3.489 0.000
L1.Vorarlberg 0.065871 0.030274 2.176 0.030
L1.Wien 0.096476 0.055667 1.733 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174702 0.060114 2.906 0.004
L1.Burgenland 0.005673 0.036590 0.155 0.877
L1.Kärnten -0.065942 0.019141 -3.445 0.001
L1.Niederösterreich -0.107539 0.076491 -1.406 0.160
L1.Oberösterreich 0.206575 0.075432 2.739 0.006
L1.Salzburg 0.054616 0.038818 1.407 0.159
L1.Steiermark 0.247041 0.051253 4.820 0.000
L1.Tirol 0.501716 0.041347 12.134 0.000
L1.Vorarlberg 0.064288 0.036510 1.761 0.078
L1.Wien -0.078248 0.067134 -1.166 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160998 0.066700 2.414 0.016
L1.Burgenland -0.001916 0.040599 -0.047 0.962
L1.Kärnten 0.062751 0.021238 2.955 0.003
L1.Niederösterreich 0.167315 0.084871 1.971 0.049
L1.Oberösterreich -0.056889 0.083696 -0.680 0.497
L1.Salzburg 0.208491 0.043071 4.841 0.000
L1.Steiermark 0.138766 0.056868 2.440 0.015
L1.Tirol 0.057046 0.045876 1.243 0.214
L1.Vorarlberg 0.146942 0.040510 3.627 0.000
L1.Wien 0.119551 0.074489 1.605 0.109
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390215 0.039256 9.940 0.000
L1.Burgenland -0.003552 0.023894 -0.149 0.882
L1.Kärnten -0.020868 0.012499 -1.670 0.095
L1.Niederösterreich 0.201813 0.049950 4.040 0.000
L1.Oberösterreich 0.230287 0.049258 4.675 0.000
L1.Salzburg 0.036626 0.025349 1.445 0.148
L1.Steiermark -0.015562 0.033469 -0.465 0.642
L1.Tirol 0.088900 0.027000 3.293 0.001
L1.Vorarlberg 0.050877 0.023842 2.134 0.033
L1.Wien 0.044315 0.043840 1.011 0.312
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036454 0.104528 0.168452 0.137249 0.097331 0.079623 0.032592 0.208517
Kärnten 0.036454 1.000000 -0.027052 0.130998 0.048647 0.084671 0.443651 -0.066980 0.089219
Niederösterreich 0.104528 -0.027052 1.000000 0.312501 0.118769 0.272581 0.066322 0.153589 0.291931
Oberösterreich 0.168452 0.130998 0.312501 1.000000 0.212167 0.294982 0.165872 0.136345 0.238752
Salzburg 0.137249 0.048647 0.118769 0.212167 1.000000 0.122413 0.091773 0.104872 0.124065
Steiermark 0.097331 0.084671 0.272581 0.294982 0.122413 1.000000 0.133680 0.107114 0.035210
Tirol 0.079623 0.443651 0.066322 0.165872 0.091773 0.133680 1.000000 0.064107 0.150326
Vorarlberg 0.032592 -0.066980 0.153589 0.136345 0.104872 0.107114 0.064107 1.000000 -0.004240
Wien 0.208517 0.089219 0.291931 0.238752 0.124065 0.035210 0.150326 -0.004240 1.000000